import Mock from "mockjs";
//处理路径传参
import { parameteUrl } from "@/utils/query-param";
import { RandomNumBoth, ArrSet } from "./index";
//左中
export default [
    {
        url: "/bigscreen/countUserNum",
        type: "get",
        response: () => {
            const a = Mock.mock({
                success: true,
                data: {
                    offlineNum: "@integer(50, 100)",
                    alarmNum: "@integer(20, 100)",
                    lockNum: "@integer(10, 50)",
                    totalNum: 368,
                },
            });
            a.data.onlineNum = a.data.totalNum - a.data.offlineNum - a.data.lockNum - a.data.alarmNum;
            return a;
        },
    },
    {
        url: "/bigscreen/countDeviceNum",
        type: "get",
        response: () => {
            const a = Mock.mock({
                success: true,
                data: {
                    alarmNum: "@integer(100, 1000)",
                    offlineNum: "@integer(0, 50)",
                    totalNum: 698,
                },
            });
            a.data.onlineNum = a.data.totalNum - a.data.offlineNum;
            return a;
        },
    },
    //左下
    {
        url: "/bigscreen/leftBottom",
        type: "get",
        response: () => {
            const a = Mock.mock({
                success: true,
                data: {
                    "list|20": [
                        {
                            provinceName: "@province()",
                            cityName: "@city()",
                            countyName: "@county()",
                            createTime: "@datetime('yyyy-MM-dd HH:mm:ss')",
                            deviceId: "6c512d754bbcd6d7cd86abce0e0cac58",
                            "gatewayno|+1": 10000,
                            "onlineState|1": [0, 1],
                        },
                    ],
                },
            });
            return a;
        },
    },
    //右上
    {
        url: "/bigscreen/alarmNum",
        type: "get",
        response: () => {
            const a = Mock.mock({
                success: true,
                data: {
                    dateList: ["2025-02", "2025-03", "2025-04", "2025-05", "2025-06", "2025-07"],
                    "numList|6": ["@integer(10000, 100000)"],
                    "numList2|6": ["@integer(10000, 100000)"],
                },
            });
            return a;
        },
    },
    //右中
    {
        url: "/bigscreen/ranking",
        type: "get",
        response: () => {
            let num = Mock.mock({ "list|80": [{ value: "@integer(50,1000)", name: "@cname()" }] }).list;
            let newNum: any = [],
                numObj: any = {};
            num.map((item: any) => {
                if (!numObj[item.name] && newNum.length < 8) {
                    numObj[item.name] = true;
                    // item.name = Mock.Random.cname();
                    newNum.push(item);
                }
            });
            let arr = newNum.sort((a: any, b: any) => {
                return b.value - a.value;
            });
            let a = {
                success: true,
                data: arr,
            };
            return a;
        },
    },
    //右下
    {
        url: "/bigscreen/rightBottom",
        type: "get",
        response: () => {
            const a = Mock.mock({
                success: true,
                data: {
                    "list|40": [
                        {
                            alertdetail: "@csentence(5,10)",
                            "alertname|1": ["水浸告警", "各种报警"],
                            alertvalue: "@float(60, 200)",
                            createtime: "2022-04-19 08:38:33",
                            deviceid: null,
                            "gatewayno|+1": 10000,
                            phase: "A1",
                            sbInfo: "@csentence(10,18)",
                            "terminalno|+1": 100,
                            provinceName: "@province()",
                            cityName: "@city()",
                            countyName: "@county()",
                        },
                    ],
                },
            });
            return a;
        },
    },
    //安装计划
    {
        url: "/bigscreen/installationPlan",
        type: "get",
        response: () => {
            let num = RandomNumBoth(26, 32);
            const a = Mock.mock({
                ["category|" + num]: ["@city()"],
                ["barData|" + num]: ["@integer(10, 100)"],
            });
            let lineData = [],
                rateData = [];
            for (let index = 0; index < num; index++) {
                let lineNum = Mock.mock("@integer(0, 100)") + a.barData[index];
                lineData.push(lineNum);
                let rate = a.barData[index] / lineNum;
                rateData.push((rate * 100).toFixed(0));
            }
            a.lineData = lineData;
            a.rateData = rateData;
            return {
                success: true,
                data: a,
            };
        },
    },
    {
        url: "/bigscreen/centerMap",
        type: "get",
        response: (options: any) => {
            let params = parameteUrl(options.url);
            //不是中国的时候
            if (params.regionCode && !["china"].includes(params.regionCode)) {
                const dataList = [
                    {
                        name: "福州市",
                        value: [119.200519, 26.047886],
                        center: [119.306239, 26.075302],
                        centroid: [119.200519, 26.047886],
                    },
                    {
                        name: "厦门市",
                        value: [118.123854, 24.676398],
                        center: [118.11022, 24.490474],
                        centroid: [118.123854, 24.676398],
                    },
                    {
                        name: "莆田市",
                        value: [118.894712, 25.445304],
                        center: [119.007558, 25.431011],
                        centroid: [118.894712, 25.445304],
                    },
                    {
                        name: "三明市",
                        value: [117.400007, 26.298093],
                        center: [117.635001, 26.265444],
                        centroid: [117.400007, 26.298093],
                    },
                    {
                        name: "泉州市",
                        value: [118.267651, 25.202187],
                        center: [118.589421, 24.908853],
                        centroid: [118.267651, 25.202187],
                    },
                    {
                        name: "漳州市",
                        value: [117.458578, 24.330766],
                        center: [117.661801, 24.510897],
                        centroid: [117.458578, 24.330766],
                    },
                    {
                        name: "南平市",
                        value: [118.147051, 27.338631],
                        center: [118.178459, 26.635627],
                        centroid: [118.147051, 27.338631],
                    },
                    {
                        name: "龙岩市",
                        value: [116.74379, 25.291574],
                        center: [117.02978, 25.091603],
                        centroid: [116.74379, 25.291574],
                    },
                    {
                        name: "宁德市",
                        value: [119.489399, 26.971518],
                        center: [119.527082, 26.65924],
                        centroid: [119.489399, 26.971518],
                    },
                ];
                const a = Mock.mock({
                    success: true,
                    data: {
                        dataList: dataList,
                        regionCode: params.regionCode, //-代表中国
                    },
                });
                return a;
            } else {
                const a = Mock.mock({
                    success: true,
                    data: {
                        "dataList|12": [
                            {
                                name: "@province()",
                                value: "@integer(1, 1100)",
                            },
                        ],
                        regionCode: "china",
                    },
                });
                // 去重
                a.data.dataList = ArrSet(a.data.dataList, "name");
                return a;
            }
        },
    },
];
